from selenium.webdriver.common.by import By

from common.utils import chromeDriver


class MyProject:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/project"
        self.driver = chromeDriver.driver
        self.driver.get(self.url)

    #页面元素检查
    def MyProjectCheckElement(self):
        #检查我的项目按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > aside > div > div:nth-child(2) > ul > li.ant-menu-item.ant-menu-item-selected.ant-menu-item-only-child.ant-pro-base-menu-menu-item > span > div > span.ant-pro-base-menu-item-text.ant-pro-base-menu-item-text-has-icon")
        #检查新建按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost.ant-page-header-compact > div.ant-page-header-heading > span > div > div > button")
        #检查搜索框是否存在
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost.ant-page-header-compact > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > input")
        #检查搜索按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost.ant-page-header-compact > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > span > button")
        #添加屏幕截图
        chromeDriver.getScreenShot()

    #功能检查
    def ProjectFuncTest(self):
        #1.问卷调查功能测试
        #点击新建按钮，添加屏幕截图
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button > span:nth-child(2)").click()
        chromeDriver.getScreenShot()
        #点击问卷调查，添加屏幕截图
        self.driver.find_element(By.CSS_SELECTOR, "body > div:nth-child(7) > div > div > ul > li:nth-child(1)").click()
        chromeDriver.getScreenShot()
        #点击保存，添加屏幕截图
        self.driver.find_element(By.CSS_SELECTOR, "#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm > span").click()
        chromeDriver.getScreenShot()

        #回退
        self.driver.back()
        self.driver.back()

        #测试搜索功能
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > input").send_keys("请输入标题")
        #点击搜索按钮
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > span > button").click()
        #添加屏幕截图
        chromeDriver.getScreenShot()

        #2.在线考试功能测试
        #点击新建按钮，添加屏幕截图
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button > span:nth-child(2)").click()
        chromeDriver.getScreenShot()
        #点击在线考试，添加屏幕截图
        self.driver.find_element(By.CSS_SELECTOR, "body > div:nth-child(9) > div > div > ul > li:nth-child(2) > span").click()
        chromeDriver.getScreenShot()
        #点击保存，添加屏幕截图
        self.driver.find_element(By.CSS_SELECTOR, "#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm > span").click()
        chromeDriver.getScreenShot()
        #后退
        self.driver.back()

        #测试搜索功能
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > input").send_keys("请输入标题")
        #点击搜索按钮
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > span > button").click()
        #添加屏幕截图
        chromeDriver.getScreenShot()

